<template>
	<div>
		<span @click="demo">sadsodjasdjlsakjdjasdjklasjdlksajd</span>
		<a href="tel://15273119291">电弧</a>
		<p @click="getplace">获取地图</p>
		<mt-actionsheet :actions="actions" v-model="sheetVisible" cancelText=""></mt-actionsheet>
	</div>
</template>

<script type="text/javascript">
	import Loading from './loading/loading'
	export default {
		components: { Loading },
		data () {
			return {
				sheetVisible: false,
				loading: false,
				list: ['a','b','c','d'],
				actions: [
					{
						name: 'aaaaa',
						method: function(){
							window.location.href = "tel://15273119291"
						}
					},
					{
						name: 'bbbbb',
						method: function(){
							window.location.href = "tel://15273119291"
						}
					}
				]
			}
		},
		async created () {
			/*
				location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3e1a57aa97195377&redirect_uri=http://www.mengxsh.cc/xunchong/yh/index.do&response_type=code&scope=snsapi_userinfo&state=uppick#wechat_redirect"
				location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3e1a57aa97195377&redirect_uri=http://www.mengxsh.cc/xunchong/yh/index.do&response_type=code&scope=snsapi_userinfo&state=uplose#wechat_redirect"

				location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3e1a57aa97195377&redirect_uri=http://www.mengxsh.cc/xunchong/yh/index.do&response_type=code&scope=snsapi_userinfo&state=lose#wechat_redirect"
				location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3e1a57aa97195377&redirect_uri=http://www.mengxsh.cc/xunchong/yh/index.do&response_type=code&scope=snsapi_userinfo&state=pick#wechat_redirect"


			*/
			this.getSign()

			// this.axios.get('api/yh/getsign.do',{
			// 	params: {
			// 		url: url
			// 	}
			// }).then(res => {
			// 	// console.log()
			// 	console.log(res)
			// })

			console.log(this.wx)

			/*
				https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3e1a57aa97195377&redirect_uri=47.91.153.55/xunchong/yh/index.do&response_type=code&scope=SCOPE&state=upload#wechat_redirect
			*/
		},
		methods: {
			demo () {
				this.sheetVisible = true;
				// this.$toast({
				//   message: '提示',
				//   duration: 5000
				// });
			},
			getplace () {
				this.wx.openLocation({
					latitude: 39.90403, // 纬度，浮点数，范围为90 ~ -90
				    longitude: 116.407526, // 经度，浮点数，范围为180 ~ -180。
				    name: 'aaa', // 位置名
				    address: 'bbb', // 地址详情说明
				    scale: 1, // 地图缩放级别,整形值,范围从1~28。默认为最大
				    infoUrl: 'http://www.baidu.com' // 在查看位置界面底部显示的超链接,可点击跳转
				})
			},
			async getSign () {
				var url = window.location.href.split("#")[0];
				// url = 'http://www.mengxsh.cc/xunchong/dist/index.html';
				url = 'http://www.jsmysoft.com/xunchong/dist/index.html';

				console.log(url)
				var res = await this.axios.get(this.$store.state.hostname + 'yh/getsign.do',{
					url: url
				})
				console.log(res)
				var self = this;
				this.wx.config({
					appId: this.$store.state.appId,
					timestamp: res.timestamp,
					nonceStr: res.nonceStr,
					signature: res.signature,
					jsApiList: [
						'getLocation',
						'openLocation',
					]
				})
				this.wx.checkJsApi({
					jsApiList: [
						'getLocation',
						'openLocation',
					],// 需要检测的JS接口列表，所有JS接口列表见附录2,
				    success: function(res) {
				    	console.log(res)
				        // 以键值对的形式返回，可用的api值true，不可用为false
				        // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
				    }
				})


				this.wx.ready(function(){
					self.wx.getLocation({
						type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
					    succdess: function (res) {
					        var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
					        var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
					        var speed = res.speed; // 速度，以米/每秒计
					        var accuracy = res.accuracy; // 位置精度
					        console.log("plae---------")
					        console.log(res)
					        console.log(latitude, longitude, speed, accuracy)
					    },
					    fail: function (res) {
					    	console.log(res)
					    }
					})
				})


			},
			loadMore() {
			  this.loading = true;
			  setTimeout(() => {
			    let last = this.list[this.list.length - 1];
			    for (let i = 1; i <= 10; i++) {
			      this.list.push(last + i);
			    }
			    this.loading = false;
			  }, 3000);
			}
		}
	}
</script>
